package controller;

import java.io.IOException;

import dao.LeaveDao;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class LeaveServlet
 */
@WebServlet("/LeaveServlet")
public class AddLeaveServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddLeaveServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
        
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		// TODO Auto-generated method stub
		boolean b = false; // ��ʼ������ֵΪ false
		String number = request.getParameter("number");
		String name = request.getParameter("name");
		String id = request.getParameter("id");
		String classroom = request.getParameter("classroom");
		String course = request.getParameter("course");
		String sdata = request.getParameter("sdata");				
		String edata = request.getParameter("edata");
		String sumdata = request.getParameter("sumdata");
		String phone = request.getParameter("phone");
		String reason = request.getParameter("reason");
		String go = request.getParameter("go");
		String address = request.getParameter("address");
		String status = request.getParameter("status");
		String refuse = request.getParameter("refuse");
		
		
		// ������Ӧ��������
        response.setContentType("text/html;charset=UTF-8");
		LeaveDao dao = new LeaveDao();
		
		//������д�����ݿ�
		b=dao.addleave(number, name, id, classroom, course, sdata, edata, sumdata, phone, reason, go, address, status, refuse);
		
		
		//д��ɹ��������ɹ���ʾ��
		if(b==true) {
			System.out.print("����嵥д��ɹ� ");			
			// ��ת�� S_Main_Leave.jsp
	        response.sendRedirect("View_leave/S_Main_Leave.jsp");
		}else {
			System.out.print("����嵥д��ʧ�� ");
		}
		
		
		
	}

}
